/* 
 * File:   main.cpp
 * Author: fer
 *
 * Created on 25 de agosto de 2011, 19:07
 */
/*This file is part of Sandbox.

Sandbox is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.

Sandbox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Sandbox.  If not, see <http://www.gnu.org/licenses/>.

For contact, see the About page of my blog: <http://mygeekyware.wordpress.com/>.*/

#include <cstdlib>
#include <iostream>
#include "particula.h"
#include <SDL/SDL.h>
#include <SDL/SDL_events.h>
#include <SDL/SDL_ttf.h>
#include "dibujar.h"
#include "controlador.h"

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    int i,j; //Acumuladores, bucles, etc;
    particula matriz[400][220]; //Matriz de juego
    controlador jefe;

    for (i=0;i< 400; i++) {
        for (j=0;j<220; j++) {
            matriz[i][j].x = i;
            matriz[i][j].y = j;
        }
    }

    cout << "TERMINADO" << endl;

    
    SDL_Surface *screen; //Definimos pantalla
    atexit(SDL_Quit);
    // Iniciar SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("No se pudo iniciar SDL: %s\n",SDL_GetError());
        exit(1);
    }

    // Activamos modo de video
    screen = SDL_SetVideoMode(800,600,24,SDL_HWSURFACE);
    if (screen == NULL) {
        printf("No se puede inicializar el modo gráfico: \n",SDL_GetError());
        exit(1);
    }

    //Activamos TTF
    if (TTF_Init() == -1) {
        printf("Imposible inicializar SDL_TFF: \n", SDL_GetError());
    }
    atexit(TTF_Quit);
    TTF_Font *sans = TTF_OpenFont("FreeSans.ttf", 10);
    //Inicializaciones
    //Crear suelo paredes, etc
    for (i = 0;i<400;i++) {
        matriz[i][0].tipo = 1;
        matriz[i][0].peso = 1000;
        matriz[i][219].tipo = 1;
        matriz[i][219].peso = 1000;
    }
    for (i = 0;i<220;i++) {
        matriz[0][i].tipo = 1;
        matriz[0][i].peso = 1000;
        matriz[399][i].tipo = 1;
        matriz[399][i].peso = 1000;
    }
    while(1) {
        SDL_PumpEvents();
        jefe.Update(matriz);
        dibujar(matriz, 0, sans, &screen, &jefe);
        Uint8 *keys = SDL_GetKeyState(NULL);
        if (keys[SDLK_ESCAPE])
            break;
    }
    return 0;
}

